<?php


namespace utils;


class Str {

    /**
     * 下划线转驼峰
     * @param $str
     * @param string $separator
     * @return string
     */
    public static function camelize($str, $separator = '_') {
        $str = $separator . str_replace($separator, " ", strtolower($str));
        return ltrim(str_replace(" ", "", ucwords($str)), $separator);
    }

    /**
     * 驼峰转下划线
     * @param $str
     * @param string $separator
     * @return string
     */
    public static function unCamelize($str, $separator = '_') {
        return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $str));
    }

}
